package gewu.suleju.controller.rabbitmp;

import gewu.suleju.model.vo.EmailCode;
import gewu.suleju.model.vo.PhoneCode;
import gewu.suleju.rbm.RbmConst;
import gewu.suleju.util.MailUtil;
import gewu.suleju.util.SMSUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RbmSimpleService {
    @Autowired
    private MailUtil mailUtil;

    @Autowired
    private SMSUtil smsUtil;

    //消费者 参数的类型要和生产者投递的消息的类型保持一致
    @RabbitListener(queues = RbmConst.SIMPLE_QUEUE)
    @RabbitHandler
    public void mail(EmailCode emailCode){

        String email = emailCode.getEmail();
        String checkCode = emailCode.getCheckCode();

        mailUtil.sendMail(email,checkCode);
    }

    //消费者 参数的类型要和生产者投递的消息的类型保持一致
    @RabbitListener(queues = RbmConst.SIMPLE_QUEUE01)
    @RabbitHandler
    public void phone(PhoneCode phoneCode){

        String phone = phoneCode.getPhone();
        String checkCode = phoneCode.getCheckCode();

        smsUtil.sendPhoneCheckCode(phone,checkCode);
    }
}
